<?php
    include_once("../../service/productService.php");
    
    $page = $_GET["p"];
    $keyword = $_GET["keyword"];
    $record_per_page = 16;
    $start_record = ($page * $record_per_page) - ($record_per_page-1);
    $products = searchKeyword($keyword, $start_record, $record_per_page);
?>

<?php
    while($product = mysql_fetch_array($products)){
?>
        <div class="product-wrapper">
        	<div class="overlay-info-wrapper">
            	<div class="top">
                	<div><?php echo getNumberBuyer($product["PRO_ID"]); ?></div>
                </div>           
                <div id="<?php echo "btn-".$product["PRO_ID"];?>" class="faourite-btn <?php echo (isset($_GET["user"])&&isLikeByUser($product["PRO_ID"],$_GET["user"]))?"active":""; ?>" <?php echo !(isset($_GET["user"])&&isLikeByUser($product["PRO_ID"],$_GET["user"]))?"onclick='".(isset($_GET['user'])? 'flyToFavourite("'.$product["PRO_ID"].'");' : '')."likeProduct($(this),".$product["PRO_ID"].");'":"" ?> ondblclick="return false;">
                </div>         
            </div>
            <div class="shop-now-btn-wrappper">
                <div class="product-price"><?php echo number_format($product["PRO_PRICE"]); ?></div>
                <div class="shop-now-btn" onclick="flyToCart(<?php echo $product["PRO_ID"];?>);addToCart(<?php echo $product["PRO_ID"];?>);">SHOP NOW</div>
            </div>
            <div class="status-logo-wrapper">
            	<div class="status-logo">
                	<?php
						if($product["PRO_STAT_ID"] != ""){
							$proStatus = findProductStatusBy($product["PRO_STAT_ID"]);
                    ?>
	    	                <img src="image/product-status/<?php echo $proStatus["PRO_STAT_ID"]."/".$proStatus["PRO_STAT_LOGO"];?>"/>
                    <?php
						}
                    ?>
                </div>
            </div>
            <?php
                if($product["DIS_ID"] != ""){
                $discount = getDiscount($product["DIS_ID"]);
            ?>
                <div class="ribbon-wrapper">
                    <div class="ribbon"><img src="image/discount/<?php echo $discount["DIS_ID"]."/".$discount["DIS_LOGO"]; ?>"/></div>
                </div>
            <?php
                }
            ?>
            <?php
                $images = findImagesOfProduct($product["PRO_ID"]);
                
                if(mysql_num_rows($images) > 0){
                    $firstImg = mysql_fetch_array($images);  
            ?>
        	   <div class="image-source"><img id="<?php echo $product["PRO_ID"];?>" src="./image/product/<?php echo $product["PRO_ID"]."/".$firstImg["IMG_PATH"]; ?>"/></div>
               
            <?php
                }else{
            ?>
                <div class="image-source"><img src=""/></div>
            <?php
                }
            ?>
               <a href="./product-detail.php?product=<?php echo $product["PRO_ID"]; ?>">
                <div class="name"><span><?php echo $product["PRO_NAME"]; ?></span></div>
               </a>
        </div>
<?php
    }
?>